home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / dev / src / BernieHeaders.lha / include / CompilerSpecific.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-15  |  8.7 KB  |  334 lines

  1. #ifndef COMPILERSPECIFIC_H
  2. #define COMPILERSPECIFIC_H
  3. /*
  4. **    $Id: CompilerSpecific.h,v 1.2 1999/02/07 14:41:01 bernie Exp $
  5. **
  6. **    Copyright (C) 1997 Bernardo Innocenti <bernie@cosmos.it>
  7. **    All rights reserved.
  8. **
  9. **    Defines wrappers for several compiler dependent constructs,
  10. **    including function attributes and register specification for
  11. **    function arguments. Supports SAS/C, gcc, EGCS, Storm C, VBCC,
  12. **    Maxon C, DICE and Aztec C.
  13. **
  14. **    You can easily add support for other compilers as well. Please
  15. **    return any changes you make to me, so I can add them to my
  16. **    personal copy of this file.
  17. **
  18. **    Here is a short description of the macros defined below:
  19. **
  20. **    LIBCALL
  21. **        Shared library entry point, with register args
  22. **
  23. **    HOOKCALL
  24. **        Hook or boopsi dispatcher entry point with arguments
  25. **        passed in registers
  26. **
  27. **    GLOBALCALL
  28. **        Attribute for functions to be exported to other modules for
  29. **        global access within the same executable file.
  30. **        Usually defined to "extern", but can be overridden for special
  31. **        needs, such as compiling all modules together in a single
  32. **        object module to optimize code better.
  33. **
  34. **    XDEF
  35. **        Attribute for symbols to be exported to other modules for
  36. **        global access within the same executable file.
  37. **        Usually defined to an empty value.
  38. **
  39. **    XREF
  40. **        Attribute for symbols to be imported from other modules
  41. **        within the same executable file.
  42. **        Usually defined to "extern".
  43. **
  44. **    INLINE
  45. **        Please put function body inline to the calling code
  46. **
  47. **    STDARGS
  48. **        Function uses standard C conventions for arguments
  49. **
  50. **    ASMCALL
  51. **        Function takes arguments in the specified 68K registers
  52. **
  53. **    REGCALL
  54. **        Function takes arguments in registers choosen by the compiler
  55. **
  56. **    CONSTCALL
  57. **        Function does not modify any global variable
  58. **
  59. **    FORMATCALL(archetype,string_index,first_to_check)
  60. **        Function uses printf or scanf-like formatting
  61. **
  62. **    SAVEDS
  63. **        Function needs to reload context for small data model
  64. **
  65. **    INTERRUPT
  66. **        Function will be called from within an interrupt
  67. **
  68. **    NORETURN
  69. **        Function does never return
  70. **
  71. **    ALIGNED
  72. **        Variable must be aligned to longword boundaries
  73. **
  74. **    UNUSED(var)
  75. **        Eclicitly specify a function parameter as being
  76. **        unused to prevent a compiler warning.
  77. **
  78. **    CHIP
  79. **        Variable must be stored in CHIP RAM
  80. **
  81. **    REG(reg,arg)
  82. **        Put argument <arg> in 68K register <reg>
  83. **
  84. **    min(a,b)
  85. **        Return the minimum between <a> and <b>
  86. **
  87. **    max(a,b)
  88. **        Return the maximum between <a> and <b>
  89. **
  90. **    abs(a)
  91. **        Return the absolute value of <a>
  92. **
  93. **    _COMPILED_WITH
  94. **        A string containing the name of the compiler
  95. */
  96.  
  97. #ifdef __SASC
  98.     /* SAS/C 6.58 or better */
  99.  
  100.     #define INLINE        static __inline
  101.     #define STDARGS        __stdargs
  102.     #define ASMCALL        __asm
  103.     #define REGCALL        __regcall
  104.     #define CONSTCALL    /* unsupported */
  105.     #define FORMATCALL    /* unsupported */
  106.     #define SAVEDS        __saveds
  107.     #define INTERRUPT    __interrupt
  108.     #define NORETURN    /* unsupported */
  109.     #define ALIGNED        __aligned
  110.     #define UNUSED(var)    var /* unsupported */
  111.     #define CHIP        __chip
  112.     #define REG(reg,arg) register __##reg arg
  113.     #define _COMPILED_WITH    "SAS/C"
  114.  
  115.     /* For min(), max() and abs() */
  116.     #define USE_BUILTIN_MATH
  117.     #include <string.h>
  118. #else
  119. #ifdef __GNUC__
  120.     /* GeekGadgets GCC 2.7.2.1 or better */
  121.  
  122.     #define INLINE        static inline
  123.     #define STDARGS        __attribute__((stkparm))
  124.     #define ASMCALL        /* nothing */
  125.     #define REGCALL        /* nothing */
  126.     #define CONSTCALL    __attribute__((const))
  127.     #define FORMATCALL(a,s,f)    __attribute__((format(a,s,f)))
  128.     #define SAVEDS        __attribute__((saveds))
  129.     #define INTERRUPT    __attribute__((interrupt))
  130.     #define NORETURN    __attribute__((noreturn))
  131.     #define ALIGNED        __attribute__((aligned(4)))
  132.     #define UNUSED(var)    var __attribute__((unused))
  133.     #define REG(reg,arg) arg __asm(#reg)
  134.     #define _COMPILED_WITH    "GCC"
  135.  
  136.     #define min(a,b)    (((a)<(b))?(a):(b))
  137.     #define max(a,b)    (((a)>(b))?(a):(b))
  138.  
  139. #if 0
  140.     #define abs(a)        (((a)>0)?(a):-(a))
  141.  
  142.     /* Inline versions of some str*() and mem*() functions
  143.      */
  144.     #define _ANSI_SOURCE
  145.     #include <string.h>
  146.     #undef _ANSI_SOURCE
  147.  
  148.     INLINE STDARGS size_t strlen (const char *src)
  149.         { const char *tmp = src; while (*tmp) tmp++; return tmp - src; }
  150.  
  151.     INLINE STDARGS int memcmp (const void *src, const void *dest, size_t n)
  152.     {
  153.         while (n--)
  154.         {
  155.             if (*((char *)src) != *((char *)dest))
  156.                 return (*((char *)src) - *((char *)dest));
  157.             ((char *)src)++;
  158.             ((char *)dest)++;
  159.         }
  160.         return 0;
  161.     }
  162.  
  163.     INLINE STDARGS void * memset (void *m, int c, size_t n)
  164.     {
  165.         void *r = m;
  166.         n++;
  167.         while (--n > 0)
  168.             *(((unsigned char *) m)++) = (unsigned char) c;
  169.         return r;
  170.     }
  171. #endif
  172. #else
  173. #ifdef __STORM__
  174.     /* StormC 2.00.23 or better */
  175.     #define INLINE        __inline
  176.     #define STDARGS        /* nothing */
  177.     #define ASMCALL        /* nothing */
  178.     #define REGCALL        register
  179.     #define CONSTCALL    /* unsupported */
  180.     #define FORMATCALL    /* unsupported */
  181.     #define SAVEDS        __saveds
  182.     #define INTERRUPT    __interrupt
  183.     #define NORETURN    /* unsupported */
  184.     #define ALIGNED        /* unsupported */
  185.     #define UNUSED(var)    var /* unsupported */
  186.     #define CHIP        __chip
  187.     #define REG(reg,arg) register __##reg arg
  188.     #define _COMPILED_WITH    "StormC"
  189.  
  190.     #define min(a,b)    (((a)<(b))?(a):(b))
  191.     #define max(a,b)    (((a)>(b))?(a):(b))
  192.     #define abs(a)        (((a)>0)?(a):-(a))
  193.  
  194.     #define _INLINE_INCLUDES
  195.     #include <string.h>
  196. #else
  197. #ifdef __VBCC__
  198.     /* VBCC 0.7 (m68k) or better */
  199.  
  200.     #define INLINE        static __inline
  201.     #define STDARGS        /* unsupported */
  202.     #define ASMCALL        /* nothing */
  203.     #define REGCALL        /* nothing */
  204.     #define CONSTCALL    /* unsupported */
  205.     #define FORMATCALL    /* unsupported */
  206.     #define SAVEDS        __saveds
  207.     #define INTERRUPT    /* unsupported */
  208.     #define NORETURN    /* unsupported */
  209.     #define ALIGNED        /* unsupported */
  210.     #define UNUSED(var)    var /* unsupported */
  211.     #define CHIP        __chip
  212.     #define REG(reg,arg) __reg(##reg) arg
  213.     #define _COMPILED_WITH    "VBCC"
  214.  
  215.     #error VBCC compiler support is untested. Please check all the above definitions
  216. #else
  217. #ifdef __MAXON__
  218.     /* Maxon C/C++ 3.0 */
  219.  
  220.     #define INLINE        static inline
  221.     #define STDARGS        /* ? */
  222.     #define ASMCALL        /* ? */
  223.     #define REGCALL        /* ? */
  224.     #define CONSTCALL    /* unsupported */
  225.     #define FORMATCALL    /* unsupported */
  226.     #define SAVEDS        /* unsupported */
  227.     #define INTERRUPT    /* unsupported */
  228.     #define NORETURN    /* unsupported */
  229.     #define ALIGNED        /* unsupported */
  230.     #define UNUSED(var)    var /* unsupported */
  231.     #define REG(reg,arg)    register __##reg arg
  232.     #define _COMPILED_WITH    "Maxon C"
  233.  
  234.     /* For min(), max() and abs() */
  235.     #define USE_BUILTIN_MATH
  236.     #include <string.h>
  237.  
  238.     #error Maxon C compiler support is untested. Please check all the above definitions
  239. #else
  240. #ifdef _DCC
  241.     /* DICE C 3.15 */
  242.  
  243.     #define INLINE        static __inline
  244.     #define STDARGS        __stdargs
  245.     #define ASMCALL        /* nothing */
  246.     #define REGCALL        /* ? */
  247.     #define CONSTCALL    /* unsupported */
  248.     #define FORMATCALL    /* unsupported */
  249.     #define SAVEDS        __geta4
  250.     #define INTERRUPT    /* unsupported */
  251.     #define NORETURN    /* unsupported */
  252.     #define ALIGNED        __aligned
  253.     #define UNUSED(var)    var /* unsupported */
  254.     #define REG(reg,arg)    __##reg arg
  255.     #define _COMPILED_WITH    "DICE"
  256.  
  257.     #define min(a,b)    (((a)<(b))?(a):(b))
  258.     #define max(a,b)    (((a)>(b))?(a):(b))
  259.     #define abs(a)        (((a)>0)?(a):-(a))
  260.  
  261.     #error DICE compiler support is untested. Please check all the above definitions
  262. #else
  263. #ifdef AZTEC_C
  264.     /* Aztec/Manx C */
  265.  
  266.     #define INLINE        static
  267.     #define STDARGS        /* ? */
  268.     #define ASMCALL        /* ? */
  269.     #define REGCALL        /* ? */
  270.     #define CONSTCALL    /* unsupported */
  271.     #define FORMATCALL    /* unsupported */
  272.     #define SAVEDS        __geta4
  273.     #define INTERRUPT    /* unsupported */
  274.     #define NORETURN    /* unsupported */
  275.     #define ALIGNED        __aligned
  276.     #define UNUSED(var)    var /* unsupported */
  277.     #define REG(reg,arg)    __##reg arg
  278.     #define _COMPILED_WITH    "Manx C"
  279.  
  280.     #define min(a,b)    (((a)<(b))?(a):(b))
  281.     #define max(a,b)    (((a)>(b))?(a):(b))
  282.     #define abs(a)        (((a)>0)?(a):-(a))
  283.  
  284.     #error Aztec/Manx C compiler support is untested. Please check all the above definitions
  285. #else
  286.     #error Please add compiler specific definitions for your compiler
  287. #endif
  288. #endif
  289. #endif
  290. #endif
  291. #endif
  292. #endif
  293. #endif
  294.  
  295.  
  296. /* CONST_STRPTR is a typedef made by a patched version of <exec/types.h>.
  297.  * Passing "const char *" parameters will only work if the OS protos are
  298.  * patched accordingly, otherwise you will get a lot of compiler warnings
  299.  * for const to volatile conversions.
  300.  *
  301.  * Using "const" where it is appropriate helps the compiler optimizing
  302.  * code better, so this mess is probably worth it. I wish one day the OS
  303.  * headers will come with support for the const keyword.
  304.  */
  305. #ifndef _CONST_STRPTR_DEFINED
  306. typedef char *CONST_STRPTR;
  307. #endif
  308.  
  309.  
  310. /* Special function attributes */
  311.  
  312. #define LIBCALL        ASMCALL SAVEDS
  313. #define HOOKCALL    ASMCALL SAVEDS
  314. #ifdef __cplusplus
  315.     #define GLOBALCALL extern "C"
  316. #else
  317.     #define GLOBALCALL
  318. #endif
  319.  
  320. /* special variable attributes */
  321. #define XDEF
  322. #define XREF extern
  323.  
  324.  
  325. /* AROS Compatibility: IPTR is a type which can store a pointer
  326.  * as well as a long integer.
  327.  */
  328. #ifndef IPTR
  329. #define IPTR LONG
  330. #endif /* IPTR */
  331.  
  332.  
  333. #endif /* !COMPILERSPECIFIC_H */
  334.